package com.zzx.wsbehind.controller;

import com.zzx.wsbehind.component.WebSocket;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @version 1.0
 * @Author ZZX
 * @Date 2022/12/15 11:03
 */
@RestController
public class TestController
{
    // 依赖注入websocket工具组件
    @Resource
    private WebSocket webSocket;

    // 测试发送信息功能
    @GetMapping("/test")
    public String test(@RequestParam("message") String message)
    {
        webSocket.sendMessage(message);
        return "发送成功";
    }

    // 测试给订阅某个主题的客户端发送消息
    @GetMapping("/test2")
    public String test2(@RequestParam("topic") String topic,@RequestParam("message") String message)
    {
        webSocket.sendMessageByTopic(message,topic);
        return "发送成功2";
    }
}
